package com.onepiece.shipelves.common.ticker;

/**
 * @author wangxj
 * @Desc: 交易对 基础信息 ，只表示最基本的字段
 * 用于market中的交易对业务流转
 * 不希望被业务类继承，只能被扩展了类继承，业务类只能复合。如果有新增的基本信息字段，直接在该类中扩展，特定的业务字段应该用其他类表示
 * @date 2020-01-13
 */
public class PairBaseInfo {

    /**
     * 币种唯一值
     */
    private String coinKey;

    /**
     * 币种简称,用于系统业务处理及访问ticker数据
     */
    private String symbol;

    /**
     * 币种展示名称，用于前端展示及与展示有关的业务处理
     */
    private String symbolShow;

    /**
     * 计价货币
     */
    private String currency;

    /**
     * 计价货币展示名称
     */
    private String currencyShow;

    /**
     * 期货类型，期货交易对才有
     */
    private String future;

    /**
     * 交易所key值
     */
    private String exchangeKey;

    /**
     * 期货交易所key值
     */
    private String exchangeFutureKey;

    /**
     * 交易对类型。1-现货，2-期货
     */
    private Integer tradeType = 1;

    /**
     * 是否异常交易对
     */
    private Integer abnormalStatus;

    public PairBaseInfo() {
    }

    public PairBaseInfo(String coinKey, String symbol, String symbolShow, String currency, String currencyShow, String exchangeKey) {
        this.coinKey = coinKey;
        this.symbol = symbol;
        this.symbolShow = symbolShow;
        this.currency = currency;
        this.currencyShow = currencyShow;
        this.exchangeKey = exchangeKey;
    }

    public PairBaseInfo(String coinKey, String symbol, String symbolShow, String currency, String currencyShow, String future, String exchangeKey, String exchangeFutureKey, Integer tradeType) {
        this.coinKey = coinKey;
        this.symbol = symbol;
        this.symbolShow = symbolShow;
        this.currency = currency;
        this.currencyShow = currencyShow;
        this.future = future;
        this.exchangeKey = exchangeKey;
        this.exchangeFutureKey = exchangeFutureKey;
        this.tradeType = tradeType;
    }

    public PairBaseInfo(String coinKey, String symbol, String symbolShow, String currency, String currencyShow, String future, String exchangeKey, String exchangeFutureKey, Integer tradeType, Integer abnormalStatus) {
        this.coinKey = coinKey;
        this.symbol = symbol;
        this.symbolShow = symbolShow;
        this.currency = currency;
        this.currencyShow = currencyShow;
        this.future = future;
        this.exchangeKey = exchangeKey;
        this.exchangeFutureKey = exchangeFutureKey;
        this.tradeType = tradeType;
        this.abnormalStatus = abnormalStatus;
    }

    /**
     * 最简单的现货交易对，通过这三个值可以确定一个现货交易对
     *
     * @param symbol
     * @param currency
     * @param exchangeKey
     */
    public PairBaseInfo(String symbol, String currency, String exchangeKey) {
        this.symbol = symbol;
        this.currency = currency;
        this.exchangeKey = exchangeKey;
    }

    public PairBaseInfo(String symbol, String currency, String future, String exchangeKey) {
        this.symbol = symbol;
        this.currency = currency;
        this.future = future;
        this.exchangeKey = exchangeKey;
        this.tradeType = 2;
    }

    /**
     * 是否是期货交易对
     *
     * @return
     */
    public Boolean future() {
        return tradeType == 2;
    }

    /**
     * 行情交易对
     *
     * @return
     */
    public String provideTickerPair() {
        if (future()) {
            return String.format("%s_%s_%s", this.symbol, this.currency, this.future);
        }
        return String.format("%s_%s", this.symbol, this.currency);
    }

    /**
     * 展示交易对
     *
     * @return
     */
    public String provideShowPair() {
        return String.format("%s_%s", this.symbolShow, this.currencyShow);
    }

    /**
     * 交易对全信息
     *
     * @return
     */
    public String provideFullTickerPair() {
        if (future()) {
            return String.format("%s_%s_%s_%s", this.exchangeFutureKey, this.symbol, this.currency, this.future);
        }
        return String.format("%s_%s_%s", this.exchangeKey, this.symbol, this.currency);
    }

    /**
     * 交易对全信息
     * 系统很多地方用现货交易所的key来组成全标记（期货的算到现货上）
     *
     * @return
     */
    public String provideSpotFullTickerPair() {
        if (future()) {
            return String.format("%s_%s_%s_%s", this.exchangeKey, this.symbol, this.currency, this.future);
        }
        return String.format("%s_%s_%s", this.exchangeKey, this.symbol, this.currency);
    }


    /**
     * 该交易对的行情交易所key值
     *
     * @return
     */
    public String provideTickerExchangeKey() {
        if (future()) {
            return this.exchangeFutureKey;
        }
        return this.exchangeKey;
    }

    public String provideExchangeCurrency() {
        return String.format("%s_%s", provideTickerExchangeKey(), this.currency);
    }

    public String provideFutureCurrency() {
        return String.format("%s_%s", this.currency, this.future);
    }

    public String provideCurrency() {
        return future() ? provideFutureCurrency() : getCurrency();
    }


    public String getCoinKey() {
        return coinKey;
    }

    public void setCoinKey(String coinKey) {
        this.coinKey = coinKey;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public String getSymbolShow() {
        return symbolShow;
    }

    public void setSymbolShow(String symbolShow) {
        this.symbolShow = symbolShow;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public String getCurrencyShow() {
        return currencyShow;
    }

    public void setCurrencyShow(String currencyShow) {
        this.currencyShow = currencyShow;
    }

    public String getFuture() {
        return future;
    }

    public void setFuture(String future) {
        this.future = future;
    }

    public String getExchangeKey() {
        return exchangeKey;
    }

    public void setExchangeKey(String exchangeKey) {
        this.exchangeKey = exchangeKey;
    }

    public String getExchangeFutureKey() {
        return exchangeFutureKey;
    }

    public void setExchangeFutureKey(String exchangeFutureKey) {
        this.exchangeFutureKey = exchangeFutureKey;
    }

    public Integer getTradeType() {
        return tradeType;
    }

    public void setTradeType(Integer tradeType) {
        this.tradeType = tradeType;
    }

    public Integer getAbnormalStatus() {
        return abnormalStatus;
    }

    public void setAbnormalStatus(Integer abnormalStatus) {
        this.abnormalStatus = abnormalStatus;
    }
}
